package util

class IntervalUtils {
	static Map<String, Long> cached = [:]

	static void put(String key){
		cached[key] = new Long(System.currentTimeMillis())
	}

	// 一段时间内是否需要refresh
	static boolean needRefresh(String key, long interval){
		Long lastRunMillis = cached[key]
		long millis = System.currentTimeMillis()

		boolean needRun = lastRunMillis == null || (millis - lastRunMillis.longValue()) >= interval

		// 保存这次调用的时间
		if(needRun)
			cached[key] = new Long(millis)
		
		needRun
	}
}